﻿Imports System.Net.Mail
Imports BookOrderingSystem.BOSDataSetTableAdapters

Public Class ForgetPassword
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub bn_send_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bn_send.Click
        Dim adap As New UsersTableAdapter
        Dim password As String = ""
        Dim userTable = adap.GetDataByUserName(tb_UserName.Text)
        If (userTable.Count = 0) Then
            lb_message.Text = "The user is not exist!"
        Else
            password = userTable(0).UserPassword

            Try
                'mail message
                Dim mM As New MailMessage()
                'Mail Address
                mM.From = New MailAddress("clymailtester@yahoo.com.hk")
                'emailid to send
                mM.[To].Add(tb_email.Text)
                'your subject line of the message
                mM.Subject = "Password"
                'now attached the file
                'mM.Attachments.Add(new Attachment(@"C:\\attachedfile.jpg"));
                'add the body of the email
                mM.Body = "Your password is " + password + "."
                mM.IsBodyHtml = False
                'SMTP 
                Dim SmtpServer As New SmtpClient()
                'your credential will go here
                SmtpServer.Credentials = New System.Net.NetworkCredential("clymailtester@yahoo.com.hk", "clypassword")
                'port number to login yahoo server
                SmtpServer.Port = 587
                'yahoo host name
                SmtpServer.Host = "smtp.mail.yahoo.com"
                'Send the email
                'MessageBox.Show("mail Send");
                SmtpServer.Send(mM)
                'end of try block
                MsgBox("Mail send.")
            Catch ex As Exception
            End Try
            'end of catch
        End If
    End Sub
End Class